Sketch in a function to recompute "track things" such as speed and heading.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 15 Apr 2006 19:16:26 +0000 (19:16 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 15 Apr 2006 19:16:26 +0000 (19:16 +0000)
gpsbabel/route.c

index 6c07cb285957ae79937f8e6bb9a9356e53560edd..b13a05da14e913c0a6c5f3f14d72557ecd2396c6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdio.h>
 #include "defs.h"
+#include "grtcirc.h"
 
 static queue my_route_head;
 static queue my_track_head;
@@ -436,3 +437,31 @@ track_restore( queue *head_bak)
        
        common_restore_finish();
 }
+
+/*
+ * This really makes more sense for tracks than routes.
+ * Run over all the trackpoints, computing heading (course), speed, and
+ * and so on.
+ */
+void track_recompute(route_head *trk)
+{
+       waypoint first;
+       waypoint *this;
+       waypoint *prev = &first;
+       queue *elem, *tmp;
+
+       first.latitude = 0;
+       first.longitude = 0;
+       first.creation_time = 0;
+
+       QUEUE_FOR_EACH((queue *)&trk->waypoint_list, elem, tmp) {
+               this = (waypoint *)elem;
+               this->course = heading(prev->latitude, prev->longitude,
+                       this->latitude, this->longitude);
+               this->speed = radtometers(gcdist(
+                       RAD(prev->latitude), RAD(prev->longitude),
+                       RAD(this->latitude), RAD(this->longitude))) /
+                       labs(this->creation_time - prev->creation_time);
+               prev = this;
+       }
+}